package com.kadron.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.validator.NotNull;

import com.kadron.base.KBase;

@Entity
@Table(name = "k_itemtype_size", uniqueConstraints = { @UniqueConstraint(columnNames = {
		"itemtype_id", "size_id" }) })
public class ItemTypeSize extends KBase implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7592122117399771560L;

	protected ItemType itemType;
	protected Size size;
	protected int ordinal;

	public ItemTypeSize() {
		super();
	}

	public ItemTypeSize(ItemType itemType, Size size, int ordinal) {
		super();
		this.itemType = itemType;
		this.size = size;
		this.ordinal = ordinal;
	}

	@NotNull
	@ManyToOne(targetEntity = ItemType.class)
	@JoinColumn(name = "itemtype_id", nullable = false)
	public ItemType getItemType() {
		return itemType;
	}

	public void setItemType(ItemType itemType) {
		this.itemType = itemType;
	}

	@NotNull
	@ManyToOne(targetEntity = Size.class)
	@JoinColumn(name = "size_id", nullable = false)
	public Size getSize() {
		return size;
	}

	public void setSize(Size size) {
		this.size = size;
	}
	
	@Column(name = "ordinal", nullable = false)
	public int getOrdinal() {
		return ordinal;
	}

	public void setOrdinal(int ordinal) {
		this.ordinal = ordinal;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((size == null) ? 0 : size.hashCode());
		result = prime * result
				+ ((itemType == null) ? 0 : itemType.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ItemTypeSize other = (ItemTypeSize) obj;
		if (size == null) {
			if (other.size != null)
				return false;
		} else if (!size.equals(other.size))
			return false;
		if (itemType == null) {
			if (other.itemType != null)
				return false;
		} else if (!itemType.equals(other.itemType))
			return false;
		return true;
	}
	
}
